<!DOCTYPE html>
<html>
<head>
    <title>小工具</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="./webjars/bootstrap/4.5.3/css/bootstrap.min.css">
    <link rel="stylesheet" href="./css/common.css">
    <script src="./webjars/jquery/3.4.1/jquery.min.js"></script>
    <script src="./webjars/popper.js/1.16.0/popper.min.js"></script>
    <script src="./webjars/bootstrap/4.5.3/js/bootstrap.min.js"></script>
    <script src="./webjars/layer/dist/layer.js"></script>
    <link rel="icon" href="./img/favicon.ico" type="image/x-icon"/>
    <link rel="shortcut icon" href="./img/favicon.ico" type="image/x-icon"/>
    <style>
        .full-h {
            flex: 1;
            display: flex;
            flex-direction: column;
        }

        .btn-width {
            width: 100px;
        }
    </style>
</head>
<body>
<div id="head">
</div>
<script>
    $("#head").load("./head.html", function () {
        $("#esbExcelToJava").addClass("active");
    });
</script>
<form class="container-fluid" style="margin-top: 5rem">
    <div class="row  mt-9 pt-3">
        <div class="col form-inline">
            <label for="className" class="mr-2">类名: </label>
            <input type="text" class="form-control mr-2" id="className" placeholder="类名" value="Test">
            <label for="classPackage" class="mr-2">包名: </label>
            <input type="text" class="form-control col-3 mr-2" id="classPackage" placeholder="包名"
                   value="com.csrcbank.web.model">
            <label for="classAuthor" class="mr-2">类作者: </label>
            <input type="text" class="form-control mr-2" id="classAuthor" placeholder="类作者" value="AUTO GEN">
            <label for="classMemo" class="mr-2">类注释: </label>
            <input type="text" class="form-control mr-2" id="classMemo" placeholder="类注释" value="无">
            <div class="form-check mr-2">
                <label class="form-check-label">
                    <input class="form-check-input" type="checkbox" id="useLombok" checked="checked"> 使用Lombok
                </label>
            </div>
            <button type="button" class="btn btn-custom" id="testBtn">示例</button>
        </div>
    </div>
    <div class="row  mt-9 pt-3" style="min-height: 600px ; ">
        <div class="col full-h">
            <div class="form-group full-h">
                <textarea class="form-control full-h" rows="4" id="classData" placeholder="classData"></textarea>
            </div>
        </div>
        <div class="col-1"
             style="display: flex;flex-direction: column;justify-content: center;    align-items: center;">
            <div class="btn-group" style="display: flex;justify-content: flex-start;">
                <button type="button" class="btn btn-custom btn-width" id="toJava">生成</button>
            </div>
        </div>
        <div class="col full-h">
            <div class="form-group full-h">
                <textarea class="form-control full-h" rows="4" id="java" placeholder="java"></textarea>
            </div>
        </div>
    </div>
</form>
</body>
<script>
    var data = "custNo\t客户号\tString\n" +
        "partyName\t客户名称\tString\n" +
        "certType\t证件类型\tString\n" +
        "certNo\t证件号码\tString\n" +
        "certNoLegalFlag\t证件号码合法性标志\tString\n" +
        "checkResult\t身份核实结果\tString\n" +
        "custChnName\t客户拼音名/英文名\tString\n" +
        "custEngName\t客户拼音姓/英文姓\tString";
    $(document).ready(function () {
        $("#testBtn").click(function () {
            $("#classData").val(data)
        });
        $("#toJava").click(function () {
            var data = {};
            data.classData = $("#classData").val();
            data.className = $("#className").val();
            data.classAuthor = $("#classAuthor").val();
            data.classMemo = $("#classMemo").val();
            data.classPackage = $("#classPackage").val();
            data.useLombok = $("#useLombok:checked").val() === 'on';
            console.log(data)
            if (!data.classData) {
                return;
            }
            var layerIndex = layer.load(2);
            convert(data, function (res) {
                layer.close(layerIndex);
                $("#java").val(res);
            });
        });
    });

    function convert(data, finish) {
        $.ajax({
            url:"/esb-excel-2-java",
            type:"POST",
            contentType:"application/json; charset=utf-8",
            data:JSON.stringify(data),
            success: function (res, status) {
                if (status === 'success') {
                    finish(res.data)
                } else {
                    finish(error());
                }
            }
        })
    }
</script>
</html>
